package cn.chuengxu._01_sync;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**======================================================================================
* @Title:
* @Description: 同步发送消息生产者
* @Author: Mr.Zhang
* @Version: 1.0
* @Date:  2022/7/25 12:21
* @Parameters:
* @Return
======================================================================================*/
public class Producer {


    public static void main(String[] args) throws Exception {
        // 1.创建生产者的对象,并指定组名
        DefaultMQProducer syncProducer = new DefaultMQProducer("sync_Producer_hello");

        // 2.连接Mq
        syncProducer.setNamesrvAddr("127.0.0.1:9876");

        // 3.启动生产者
        syncProducer.start();

        // 4.创建所需要发送的消息,第一个是填写消息的主题,第二个是消息的下级路径.第三个是消息的内容
        Message message = new Message("sync_Hello","hello","Java复杂难学,趁早转行".getBytes(StandardCharsets.UTF_8));

        // 5.发送消息
        SendResult send = syncProducer.send(message);
        System.out.println(send);

        // 6.关闭生产者
        syncProducer.shutdown();

    }

}
